package com.wyl.studyredis.framework;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author 吴宇亮 on 2022/2/11 11:33
 */
@Data
public class ResponseVo<Entity> implements Serializable {

    private int code;
    private String msg;
    private Entity data;

    public static ResponseVo success(){
        ResponseVo vo = new ResponseVo();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    public static <Entity> ResponseVo<Entity> success(Entity data){
        ResponseVo<Entity> vo = new ResponseVo<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }

    public static ResponseVo fail(String msg){
        ResponseVo vo = new ResponseVo();
        vo.setCode(HttpStatus.BAD_REQUEST.value());
        vo.setMsg(msg);
        return vo;
    }

    public static ResponseVo error(String msg){
        ResponseVo vo = new ResponseVo();
        vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        vo.setMsg(msg);
        return vo;
    }


}
